<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="struts-html.tld" prefix="html"%>
<%@ taglib uri="struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="struts-logic.tld" prefix="logic"%>
<%@ taglib uri="struts-bean.tld" prefix="bean"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ipb" uri="/WEB-INF/conf/tld/ipb.tld"%>
<%@ taglib prefix="ad" uri="agiledata"%>
<%@ page import="java.util.List"%>
<%@ page import="cn.agiledata.bank.common.util.Constant"%>
<%@ page import="cn.agiledata.bank.hibernateBean.SubAccount"%>
<%@ page import="cn.agiledata.bank.account.service.AccountSummary"%>

<% 
	String path = request.getContextPath();
	AccountSummary user = (AccountSummary) session.getAttribute(Constant.SESSION_ACCOUNT_SUMMARY);
 
			
	String subAccountKey = request.getParameter("key");
	SubAccount sub = user.getSubAccountById(subAccountKey);
	List list = user.getSubAccountList();
	StringBuffer accountId = new StringBuffer();
	StringBuffer accountName = new StringBuffer();
	if(list != null) {
		for(int i=0;i<list.size();i++) {
			SubAccount subAccount = (SubAccount)list.get(i);
			if(i != 0) {
				accountId.append(",").append(subAccount.getAccountId());
				accountName.append(",").append(subAccount.getAccountName());
			} else {
				accountId.append(subAccount.getAccountId());
				accountName.append(subAccount.getAccountName());			
			}
			
		}
	}
	String ids = accountId.toString();
	String names = accountName.toString();
	
	//long defSubaccountId = user.getDefaultSubAccountId();
	
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title></title>
		<link href="<%=path%>/css/sinfo.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/style.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/newstyle.css" rel="stylesheet" type="text/css" />
<link href="<%=path%>/css/common.css" rel="stylesheet" type="text/css" />
		<script type='text/javascript' src='<%=path%>/js/vnv/commonForManage.js'></script>
		<script type='text/javascript' src='<%=path%>/dwr/util.js'></script>
		<script type='text/javascript' src='<%=path%>/dwr/engine.js'></script>
		<script type='text/javascript' src='<%=path%>/dwr/interface/subAccountService.js'></script>
		<script language="JavaScript" type="text/JavaScript">
function submitProcess() {
		if(checkNecessaryInput(document.forms["0"]) && checkInputMaxlength(document.forms["0"]))
		{
		   document.forms["0"].submit();
		  }
}

function isUniqueSubAccountId(obj) {
	var value = obj.value;
	var temp;
	var ids = "<%=ids%>".split(",");
	for(var i=0;i<ids.length;i++){	
		if(ids[i]==value && value != "") {
			temp = false;
			break;
			
		}else{
			temp = true;
		}
	}
	return temp;
	
}

function isUniqueSubAccountName(obj){
	var value = obj.value;
	var temp;
	var names = "<%=names%>".split(",");
	for(var i=0;i<names.length;i++){
		if(names[i]==value && value != ""){
			temp = false;
		}else{
			temp = true;
		}
		if(temp==false) {
			alert("该账户名已使用，请重新添加子账户");document.getElementById("subAccountName").value="";document.getElementById("subAccountName").focus();
			return;
		}
	}
}

function sure(){
	killSpace(document.getElementById("subAccountId"));
	if(!isUniqueSubAccountId(document.getElementById("subAccountId"))){
		alert("账户名称重复,请重新添加子账户!");
		history.back();
		
	}else{
		submitProcess();	
		
	}
}

function autoSubAccountId(){
	document.getElementById("subAccountId").value="<bean:write name="defSubAccountId" />";
	document.getElementById("subAccountName").focus();
}

function notAutoSubaccountId(){
	document.getElementById("subAccountId").focus();
	document.getElementById("subAccountId").value="";
}

function load(){
	document.getElementById("subAccountName").focus();
}
</script>
		<link href="<%=path%>/css/sinfo.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/style.css" rel="stylesheet" type="text/css" />

	</head>

	<body onload="load()">
		
<div class="panel"> <html:form action="addSubAccount.do"> 
  <input type="hidden" name="subId" value="" />
  <table width="732" border="0" align="center" cellpadding="0" cellspacing="3" bgcolor="0EA2D6">
    <tr> 
      <td  bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="25" align="center" background="<%=path%>/images/new/blue_pic_01.gif"><strong><font color="#FFFFFF" style="font-size:12px">添加子账户</font></strong></td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="8" ></td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="8">
          <tr> 
            <td><table width="100%" align="center" cellpadding="3" cellspacing="1" class="form">
                <tr> 
                  <th bgcolor="F0FAFD"> 账户代码： </th>
                  <td bgcolor="F0FAFD"> <bean:define id="defSubAccountId" name="defSubAccountId"/> 
                    <input class="disedit" name="subAccountId" value="<%=defSubAccountId%>" readonly="readonly"/>
                    *&nbsp;&nbsp;&nbsp;(账户代码由系统自动生成,用来标识账户) </td>
                  <!-- 
						<td colspan="2" style="text-align:right;">
							<BUTTON class="button_3" onclick="autoSubAccountId()">自动生成</BUTTON>
						
							<button class="button_3" onclick="notAutoSubaccountId()">手工填写</button>
						</td>
						-->
                </tr>
                <tr> 
                  <th> 账户名称： </th>
                  <td> <input name="subAccountName" alt="账户名称" onblur="killSpace(this);isUniqueSubAccountName(this)" maxlength="32"/>
                    *</td>
                </tr>
                <tr> 
                  <th bgcolor="F0FAFD"> Wap账户： </th>
                  <td bgcolor="F0FAFD"> <html:radio property="detailFlag" value="Y">是</html:radio> 
                    &nbsp; <html:radio property="detailFlag" value="N">否</html:radio> 
                  </td>
                </tr>
                <tr> 
                  <th> 备注： </th>
                  <td> <textarea name="subAccountRemark" cols="45" rows="5" title="maxlength:255;title:备注"></textarea>
                     </td>
                </tr>
                <tr> 
                  <td colspan="2"> <hr noshade="noshade" size="2" color="#0EA2D6" /> 
                  </td>
                </tr>
                <tr>
                  <td colspan="2" style="text-align:right;"> <img  style="cursor:pointer; margin-right:5px;" onclick="sure()" src="<%=path%>/images/new/ok_button.gif"  />
                  <img  style="cursor:pointer; margin-right:5px;" src="<%=path%>/images/new/return.gif" onClick="history.back();" /> 
                     
                  </td>
                </tr>
              </table>
              
            </td>
          </tr>
        </table></td>
    </tr>
  </table>
  </html:form> </div>
	</body>
</html>
